package com.kainitram.undo;

import java.sql.SQLException;
import java.util.List;

import com.kainitram.library.BaseArrayAdapter;
import com.kainitram.library.BaseListFragment;
import com.kainitram.morm.Model;

/**
 * Command which delete items.
 * 
 * @author Mino
 * 
 */
public class DeleteCommand<T extends Model> extends UndoRedoBaseCommand {

	private BaseListFragment<T> listFragment;
	private List<T> itemsToDelete;
	private BaseArrayAdapter<T> dataAdapter;

	public DeleteCommand(BaseListFragment<T> listFragment,
			List<T> itemsToDelete, BaseArrayAdapter<T> dataAdapter) {
		this.listFragment = listFragment;
		this.itemsToDelete = itemsToDelete;
		this.dataAdapter = dataAdapter;
	}

	public void undo() {

	}

	public void redo() {

	}

	public void execute(Object param) {
		try {
			for (T item : itemsToDelete) {
				this.dataAdapter.remove(item);
			}
			this.listFragment.getDao().delete(itemsToDelete);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
